//
//  QYGUserView.m
//  wawaji_ios
//
//  Created by 云+物娱 on 2017/12/2.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGUserView.h"

@interface QYGUserView()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong, readwrite) UIButton *headerBtn;

@end

@implementation QYGUserView

- (void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    self.nameLabel.text = nameStr;
}

- (void)setHeaderStr:(NSString *)headerStr{
    _headerStr = headerStr;
    [self.headerBtn setImageWithURL:[NSURL URLWithString:headerStr] forState:UIControlStateNormal placeholder:nil];
    
}

- (void)userViewWithName:(NSString *)name headerStr:(NSString *)headerStr{
    _nameStr = name;
    _headerStr = headerStr;
    
    self.nameLabel.text = name;
    [self.headerBtn setBackgroundImageWithURL:[NSURL URLWithString:headerStr] forState:UIControlStateNormal placeholder:nil];
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        
        
        [self initUI];
    }
    return self;
}

#pragma mark setUI
- (void)initUI{
    
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    
    self.layer.cornerRadius = ScaleW(17);
    self.layer.masksToBounds = YES;
    
    [self addSubview:self.headerBtn];
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
    
    
    [self.headerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(ScaleW(5));
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@(ScaleW(24)));
        make.height.equalTo(@(ScaleW(24)));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerBtn.mas_right).offset(ScaleW(5));
        make.top.equalTo(self.headerBtn.mas_top);
        make.right.equalTo(self.mas_right).offset(-5);
    }];
    
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(ScaleW(3));
    }];
}
#pragma mark - lazy
- (UILabel *)detailLabel{
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"游戏中..." setFont:ScaleFont(9) setTextColor:[UIColor colorWithHex:@"ffffff"] setTextAlignment:NSTextAlignmentLeft];
        _detailLabel.numberOfLines = 1;
    }
    return _detailLabel;
}

- (UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel labelWithText:@"" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"ffffff"] setTextAlignment:NSTextAlignmentLeft];
        _nameLabel.numberOfLines = 1;
//        _nameLabel.textAlignment = NSTextAlignmentCenter;
//        _nameLabel.backgroundColor = [UIColor colorWithHex:@"a54747"];
        
    }
    return _nameLabel;
}
- (UIButton *)headerBtn{
    if(!_headerBtn){
        _headerBtn = [UIButton buttonWithBackgroundImageName:@""];
        _headerBtn.backgroundColor = [UIColor whiteColor];
//        _headerBtn.size = CGSizeMake(ScaleW(30), ScaleW(30));
        _headerBtn.layer.cornerRadius = ScaleW(12);
        _headerBtn.layer.masksToBounds = YES;
     
    }
    return _headerBtn;
}
@end
